/*******************************************************************************
WHAT THIS DO FILE DOES

    This do file should be customized by users. It declares key path names, 
    checks the needed directory structure, and installs any user-written packages
    that are needed. 

    Authors:
	Francis Kubinec 2025
    
*******************************************************************************/

****************************CUSTOMIZE THE LINE BELOW****************************
global maindir "C:\Users\wb371044\OneDrive - WBG\Political Connections\Replication Package" // CHANGES BY USER

************************ DO NOT MODIFY THE CODE BELOW ***************************

* Assign globals to directory names
global out "${maindir}\out"
    global outfigures 	"${out}\Figures"
    global outtables 	"${out}\Tables"
global in "${maindir}\in"
    global inprocdta 	"${in}\Processed data"
global programs 		"${maindir}\programs"
global dofiles			"${maindir}\Stata_do files"

* Assign the necessary global to the main dta file 
global maindta "${inprocdta}\data_for_analysis.dta"
global itemdta "${inprocdta}\itemdiscrimination.csv"

* Check to see if the following directories exist
	noi di in yellow "CHECKING THAT THE REQUIRED DIRECTORIES EXIST"    
	foreach dir in out outfigures outtables outdta in inprocdta shpfiles {
		mata : st_numscalar("`dir'_ck", direxists("${`dir'}"))
		if `dir'_ck == 0 {
			noi di in red "${`dir'} does not exist."
			capture mkdir "${`dir'}"
			if !_rc {
				noi di in green "${`dir'} created." 
			}
		}
		mata : st_numscalar("`dir'_ck", direxists("${`dir'}"))
		if `dir'_ck == 0 {
			noi di in red "Error: ${`dir'} could not be created. Check permissions or path validity."
			exit 1
		}
	}
	noi di in green "ALL REQUIRED DIRECTORIES NOW FOUND"
	noi di " "

* Check to see that the main dta file is there and where it should be
	mata : st_numscalar("file_ck", fileexists("${maindta}"))
	if file_ck == 0 {
		noi di in red "Error: Main data file ${maindta} not found where it is expected to be."
		noi di in red "Ensure the file is saved in: ${inprocdta}"
		exit 
	}
	
* Check to see that the item discrimination output is where it should be 
	mata : st_numscalar("file_ck", fileexists("${itemdta}"))
	if file_ck == 0 {
		noi di in red "Error: Main data file ${maindta} not found where it is expected to be."
		noi di in red "Ensure the file is saved in: ${inprocdta}"
		exit 
	}